package net.zjitc.servlet;

import javax.servlet.*;
import java.io.IOException;

public class AServelt implements Servlet {
   private int count = 0;
   //ServletConfig：两方面配置：1、本身Servelt配置 2、来自于项目
   private ServletConfig servletConfig;
      @Override
    public void init(ServletConfig servletConfig) throws ServletException {
       this.servletConfig = servletConfig;
        System.out.println("init...");
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    //访问时servet的时候，打印出的我名字
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        count++;
        String value = servletConfig.getInitParameter("name");

        System.out.println(value);
        System.out.println(" aServlet  count = "+count);

        //当前servlet名字
        String servletName = servletConfig.getServletName();
        System.out.println("servletName = "+servletName);
        //获得的是ServletContext相关
        String contextPath = servletConfig.getServletContext().getContextPath();
        System.out.println(contextPath);
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        System.out.println("destroy...");
    }
}
